package com.restkeeper.service;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.restkeeper.dto.AliyunMessageDto;
import com.restkeeper.model.aliyun.SmsMessageDto;
import com.restkeeper.utils.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 阿里云服务实现类
 *
 * @author makejava
 * @since 2024-10-18 17:17:54
 */
@Service("aliyunService")
@RequiredArgsConstructor
@Slf4j
public class AliyunServiceImpl implements AliyunService {

    private final CommonService commonService;

    @Override
    public Result alarm(AliyunMessageDto dto) {
        /**设备名称:S{deviceName),IMEl号:${serialNumber,报警原因:S{content},报警时间:${createTime}*/
        //封装短信内容
        JSONObject senData=new JSONObject();
        senData.put("deviceName",dto.getDeviceName());
        senData.put("serialNumber",dto.getSerialNumber());
        senData.put("content",dto.getContent());
        senData.put("createTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

        SmsMessageDto messageDto=new SmsMessageDto();
        messageDto.setTemplateKey(dto.getSendKey());
        messageDto.setTemplateParam(senData.toJSONString());
        messageDto.setPhoneNumbers(dto.getPhoneNumbers());
        //发送短信
        SendSmsResponse sendSmsResponse = commonService.sendSms(messageDto);

//        commonService.sendSingleCallToUser(voiceDto);
        log.info("语音播放结");
        return Result.ok();
    }
}
